
    // 获取元素
    const imgs = document.querySelectorAll('.slider img');
    const prevBtn = document.querySelector('.prev');
    const nextBtn = document.querySelectorAll('.next')[0];
    let currentIndex = 0;

    // 显示指定索引的图片
    function showImage(index) {
      imgs.forEach((img, i) => {
        if (i === index) {
          img.classList.add('active');
        } else {
          img.classList.remove('active');
        }
      });
    }

    // 切换到下一张图片
    function nextImage() {
      currentIndex = (currentIndex + 1) % imgs.length;
      showImage(currentIndex);
    }

    // 切换到上一张图片
    function prevImage() {
      currentIndex = (currentIndex - 1 + imgs.length) % imgs.length;
      showImage(currentIndex);
    }

    // 自动轮播
    setInterval(nextImage, 1500);
  
    // 绑定按钮点击事件
    prevBtn.addEventListener('click', prevImage);
    nextBtn.addEventListener('click', nextImage);
    const galleryImages = document.querySelectorAll('.gallery img');
    const modal = document.getElementById('myModal');
    const modalImg = document.getElementById('modalImg');
    const closeButton = document.getElementsByClassName('close')[0];

    galleryImages.forEach((img) => {
      img.addEventListener('click', () => {
        modal.style.display = 'block';
        modalImg.src = img.src;
      });
    });

    closeButton.addEventListener('click', () => {
      modal.style.display = 'none';
    });

    window.addEventListener('click', (event) => {
      if (event.target === modal) {
        modal.style.display = 'none';
      }
    });
    